{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.\n",
    "\n",
    "# Capture the Flag Toy Example - Interactive (Human player)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is a blank instantiaion of the Capture The Flag network to be play interactively by a human player (not via the gym envrionment).\n",
    "The interface exposed to the attacker is given by the following commands:\n",
    "    - c2.print_all_attacks()\n",
    "    - c2.run_attack(node, attack_id)\n",
    "    - c2.run_remote_attack(source_node, target_node, attack_id)\n",
    "    - c2.connect_and_infect(source_node, target_node, port_name, credential_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys, logging\n",
    "import cyberbattle.simulation.model as model\n",
    "import cyberbattle.simulation.commandcontrol as commandcontrol\n",
    "import cyberbattle.samples.toyctf.toy_ctf as ctf\n",
    "import plotly.offline as plo\n",
    "plo.init_notebook_mode(connected=True)\n",
    "logging.basicConfig(stream=sys.stdout, level=logging.INFO, format=\"%(levelname)s: %(message)s\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "network = model.create_network(ctf.nodes)\n",
    "env = model.Environment(network=network, vulnerability_library=dict([]), identifiers=ctf.ENV_IDENTIFIERS)\n",
    "env"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "env.plot_environment_graph()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c2 = commandcontrol.CommandControl(env)\n",
    "dbg = commandcontrol.EnvironmentDebugging(c2)\n",
    "def plot():\n",
    "    dbg.plot_discovered_network()\n",
    "    c2.print_all_attacks()\n",
    "plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2-final"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}